package com.burstly.lib.exception;

import com.burstly.lib.BurstlySdk;
import com.burstly.lib.constants.Constants;
import com.burstly.lib.util.Utils;
import com.burstly.lib.util.Utils.DebugWrapper;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public final class UiExceptionHandlerManager
{
  private static final Utils.DebugWrapper DEBUG_WRAPPER = Utils.DebugWrapper.getDebugger("UiExceptionHandlerManager");
  private static final String TAG = "UiExceptionHandlerManager";
  private static boolean sIsInitialized;

  public static void cleanUp()
  {
    UnhandledExceptionWrapper.HANDLERS.clear();
  }

  public static void init()
  {
    Thread localThread;
    try
    {
      if (sIsInitialized)
        break label77;
      localThread = Thread.currentThread();
      if (!localThread.getName().equals("main"))
        throw new IllegalStateException("Can not initialize manager not in UI thread");
    }
    finally
    {
    }
    localThread.setUncaughtExceptionHandler(new UnhandledExceptionWrapper(localThread.getUncaughtExceptionHandler(), null));
    if (Constants.IS_DEBUG_MODE)
      registerHandler(new HeapFileDumpHandler());
    sIsInitialized = true;
    label77:
  }

  public static void registerHandler(Thread.UncaughtExceptionHandler paramUncaughtExceptionHandler)
  {
    if (!UnhandledExceptionWrapper.HANDLERS.add(paramUncaughtExceptionHandler))
    {
      unRegisterHandler(paramUncaughtExceptionHandler);
      UnhandledExceptionWrapper.HANDLERS.add(paramUncaughtExceptionHandler);
    }
  }

  public static void unRegisterHandler(Thread.UncaughtExceptionHandler paramUncaughtExceptionHandler)
  {
    UnhandledExceptionWrapper.HANDLERS.remove(paramUncaughtExceptionHandler);
  }

  private static final class UnhandledExceptionWrapper
    implements Thread.UncaughtExceptionHandler
  {
    private static final Set<Thread.UncaughtExceptionHandler> HANDLERS = new HashSet();
    private final Thread.UncaughtExceptionHandler mDefaultHandler;

    private UnhandledExceptionWrapper(Thread.UncaughtExceptionHandler paramUncaughtExceptionHandler)
    {
      this.mDefaultHandler = paramUncaughtExceptionHandler;
    }

    public void uncaughtException(Thread paramThread, Throwable paramThrowable)
    {
      UiExceptionHandlerManager.DEBUG_WRAPPER.logAll();
      if ((!(paramThrowable instanceof OutOfMemoryError)) && (!(paramThrowable.getCause() instanceof OutOfMemoryError)))
        Utils.addInStackTrace(paramThrowable, "BurstlySDK=" + BurstlySdk.getSdkVersion() + "-" + Constants.BUILD_ID);
      Iterator localIterator = HANDLERS.iterator();
      while (localIterator.hasNext())
        ((Thread.UncaughtExceptionHandler)localIterator.next()).uncaughtException(paramThread, paramThrowable);
      this.mDefaultHandler.uncaughtException(paramThread, paramThrowable);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.exception.UiExceptionHandlerManager
 * JD-Core Version:    0.6.2
 */